package com.mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class BaseController {
	@Autowired
	public Environment env;

	public HttpServletResponse getHttpResponse() {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		return requestAttributes.getResponse();
	}

	public HttpServletRequest getHttpRequest() {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		return requestAttributes.getRequest();
	}

	/**
	 * 判断是图片还是视频
	 * @param icon
	 * @return
	 */
	public Boolean checkIconType(String icon){
		String img = "gif,jpg,jpeg,png,bmp";
		String ext=icon.substring((icon.lastIndexOf(".")+1),icon.length()).toLowerCase();
		if(img.contains(ext)){//图片
			return true;
		}else{//文件
			return false;
		}
	}

}
